//org.jackysoft.workflow.bizness.util.CheckActionStatusCondition
package org.jackysoft.workflow;

import java.util.Map;

import org.jackysoft.entity.Variable;
import org.jackysoft.entity.WorkflowEntry;
import org.jackysoft.opensymphony.workflow.Condition;
import org.jackysoft.opensymphony.workflow.WorkflowException;
import org.jackysoft.service.VariableService;

/**
 * <blockquote>
 * 检查用户动作的状态,每一个步骤回退回来后都有对应的状态
 * 来限制action对起草者可见,这个条件主要用来检查当前
 * 给定的status是否和用户当前所处的status是否同一
 * 状态
 * </blockquote>
 * 
 * */
public class CheckActionStatusCondition implements Condition {
    
	@Override
	public boolean passesCondition(Map<String,Object> transientVars, Map<String,String> args,
			VariableService vservice) throws WorkflowException {
		String status = (String) args.get(TechActionStatus.STATUSNAME.toString());
		if (status == null)
			throw new IllegalArgumentException("未设置适当的参数 ["
					+ TechActionStatus.STATUSNAME + "]");
		WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
		Variable wv = vservice.get(entry.getId(), TechActionStatus.STATUSNAME.toString());
		if(wv==null)
			return false;
		else{
			String ts  = wv.getValue();
			return status.equals(ts);
		}
	}

}
